/**
 *
 *               Copyright (c) 2011 by NCS
 *
 * All rights reserved.  These materials are confidential and
 * Proprietary to NCS. And no part of these materials
 * should be reproduced, published in any form by any means,
 * electronic or mechanical, including photocopy or any
 * Information storage or retrieval system nor should the
 * materials be disclosed to third parties without the express
 * written authorization of NCS.
 *
 *<Class Description>
 *
 *<Change Revision>
 *====================================================
 *	Date        	Version    	Author              	Remarks
 *	28/Jun/2011  	1.0        	Tang Bin Benoit    	New File.
 *
 */

package net.binkylin;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

public class SpringContextHolder implements ApplicationContextAware {

	private static ApplicationContext appContext;

	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		setAppContext(applicationContext);
	}

	public static ApplicationContext getAppContext() {
		return appContext;
	}

	public static void setAppContext(ApplicationContext appContext) {
		SpringContextHolder.appContext = appContext;
	}

	public static <T> T getBean(String name, Class<T> requiredType) {
		return appContext.getBean(name, requiredType);
	}

	public static <T> T getBean(Class<T> requiredType) {
		return appContext.getBean(requiredType.getName(), requiredType);
	}

}
